package com.lws.framework.module;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/controllerTest.do")
public class ControllerTest {

    @RequestMapping(params = "method=test")
    public void testAA(HttpServletRequest request) throws SQLException, ClientProtocolException, IOException {
        HttpClient httpclient = new DefaultHttpClient();
        String path = "https://" + request.getServerName() //
                        + ":8443/idCode.do?method=randomIDCode";
        HttpGet httpget = new HttpGet(path);
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        InputStream instream = entity.getContent();

        int len = 0;
        byte[] bytes = new byte[2048];
        while ((len = instream.read(bytes)) != -1) {
            System.out.print(new String(bytes, 0, len));
        }
    }

}
